
log using "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\data\logfile-isq.txt", text replace


*************************************************************
*************************************************************
*************************************************************
*
*
*
*				DO WALLS WORK?
*
*				Christopher Linebarger
*						&
*				Alex Braithwaite
*
*				May 14, 2020
*
*************************************************************
*************************************************************
*************************************************************



*************************************************************
* ANALYSIS
*************************************************************

use  "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\data\walldata-isq.dta", clear


********************************************************
*TABLE 1: CROSS TAB
********************************************************

tab receiveremerge lagwall  if   senderpersist==1 & year > 1975 , col expected chi2




********************************************************
*TABLE 2: MODEL 1 - EDTG
********************************************************



*M1
logit receiveremerge i.lagwall c.interact_dir  py*  if   senderpersist==1 & year > 1975 , robust cl(dyad2)

		#delimit;
		outreg2 using "C:\Users\Chris\OneDrive\Desktop\Results\model1.xls", 
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
		e(all)  excel replace;
	
	

********************************************************
*TABLE 2: MODEL 2 - EDTG
********************************************************



*M2
logit receiveremerge i.lagwall##c.interact_dir  py*  if   senderpersist==1 & year > 1975 , robust cl(dyad2)



		#delimit;
		outreg2 using "C:\Users\Chris\OneDrive\Desktop\Results\model2.xls", 
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
		e(all)  excel replace;
	
	


********************************************************
*TABLE 2: MODEL 3 - EDTG
********************************************************
		
*M3	
#delimit;
logit receiveremerge i.lagwall##c.interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem lagreceivercaplarge py*  
	if   senderpersist==1 & year > 1975 , robust cl(dyad2);
	
		
		#delimit;
		outreg2 using "C:\Users\Chris\OneDrive\Desktop\Results\model3.xls", 
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
		e(all)  excel replace;
	
	
			gen sample1 = e(sample);
	
******************	
*FIGURE 1: plot of M3
******************


#delimit;		
	predict p;
	label variable interact_dir "Border accessibility";
	#delimit;
		graph twoway 
		(histogram interact_dir if sample1==1, percent scheme(s1mono)  yaxis(1)  ytitle("Percentage of Observations",size(medlarge) 		axis(1)))
		(lfitci p  interact_dir if sample1==1 & lagwall==0, lcolor(gs2) lpattern(dash dot) yaxis(2) clwidth(thick) ytitle("", 	size(medlarge) axis(2)) )  
		(lfitci p  interact_dir if sample1==1 & lagwall==1, lcolor(gs2)  xtitle(, size(medlarge)) yaxis(2) clwidth(thick) ytitle("Pr(Militant group emergence)", 		size(medlarge) axis(2)) 
		),
		legend(order(5 "Border fortification=1" 3 "Border fortification=0" 2 "95% CI" 1 "Border accessibility") col(1) ); 
	graph export "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\text\subeffects1.tif", as(tif)    replace width(1000);
drop p;


			
******************		
*APPENDIX F: model diagnostics of M3 
******************
****	
*Check VIF and Tolerance (table 10)
****

#delimit;
	collin  completewall interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem lagreceivercaplarge   
	if   senderpersist==1 & year > 1975 ;

****	;
*check for influential observations in M3;
****;
gen wallXinteract = completewall * interact_dir;

****
*run model
****
	#delimit;
		logit receiveremerge wallXinteract completewall interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem 			lagreceivercaplarge py* if senderpersist==1 & year > 1975 , robust cl(dyad2);

****
*plot leverage (Figure 5)
****
		#delimit;
		gen id=_n;
		predict hat, hat;
		predict p;
		scatter hat p,  yline(0.05) ytitle(Leverage) xtitle(Pr(Militant group emergence)) scheme(s1mono);
			graph export "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\text\leverage1.eps",replace;
		
****
*Table 12		*repeat M3 with influencial obs removed;
****
		#delimit;
		logit receiveremerge wallXinteract completewall interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem 			lagreceivercaplarge py*  if senderpersist==1 & year > 1975 & hat < .05, robust cl(dyad2); 
			outreg2 using "C:\Users\Chris\OneDrive\Desktop\robust1.xls", 
			alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
			e(all)  excel replace;
			

drop id hat p;
		
	
	
	
	
********************************************************
*APPENDIX D3: ALTERNATIVE MODELS - Jones/Libicki models
********************************************************
#delimit;
********************************************************	
*M4
********************************************************

logit receiverbinaryemerge i.lagwall  jl*   if   senderbinarypersist==1 & year > 1975  & year < 2007, robust cl(dyad2);

********************************************************
*M5
********************************************************
logit receiverbinaryemerge i.lagwall####c.interact_dir jl*   if   senderbinarypersist==1 & year > 1975  & year < 2007, robust cl(dyad2);

********************************************************	
*M6
********************************************************
#delimit;
logit receiverbinaryemerge i.lagwall##c.interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem lagreceivercaplarge jl*   if   senderbinarypersist==1 & year > 1975  & year < 2007, robust cl(dyad2);
		gen sample2 = e(sample);
		#delimit;
		outreg2 using "C:\Users\Chris\OneDrive\Desktop\Results\model6.xls", 
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
		e(all)  excel replace;
		

	
	
	
******************		
*model diagnostics of M6
******************	

********		
*Check VIF and Tolerance (Table 11)
********
	
#delimit;
	collin  completewall interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem lagreceivercaplarge   
	if   senderbinarypersist==1 & year > 1975 ;

	
	
********		
	*check for influential observations in M6
********

	#delimit;
		logit receiverbinaryemerge wallXinteract completewall interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem 			lagreceivercaplarge  jl* if senderbinarypersist==1 & year > 1975 , robust cl(dyad2); 
		#delimit;
		gen id=_n;
		predict hat, hat;
		predict p;
		scatter hat p, yline(0.03) ytitle(Leverage) xtitle(Pr(Militant group emergence)) scheme(s1mono);
			graph export "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\text\leverage2.eps",replace;

********
*Figure 5	*repeat M6 with influencial obs removed;
********

		#delimit;
		logit receiverbinaryemerge wallXinteract completewall interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem 			lagreceivercaplarge  jl*  if senderbinarypersist==1 & year > 1975 & hat < .03, robust cl(dyad2); 
			outreg2 using "C:\Users\Chris\OneDrive\Desktop\robust2.xls", 
			alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
			e(all)  excel replace;
		drop id hat p;
		
	
	
	
 

 
****************************
*APPENDIX E: RANDOM EFFECTS MODELS
****************************




*M1
#delimit;
xtlogit receiveremerge i.lagwall c.interact_dir  py*  if   senderpersist==1 & year > 1975 , re;
			outreg2 using "C:\Users\Chris\OneDrive\Desktop\re1.xls", 
			alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
			e(all)  excel replace;

*M2
#delimit;
xtlogit receiveremerge i.lagwall##c.interact_dir  py*  if   senderpersist==1 & year > 1975 , re;
			outreg2 using "C:\Users\Chris\OneDrive\Desktop\re2.xls", 
			alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
			e(all)  excel replace;

*M3
#delimit;
xtlogit receiveremerge i.lagwall##c.interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem lagreceivercaplarge py*  if   senderpersist==1 & year > 1975 , re;
			outreg2 using "C:\Users\Chris\OneDrive\Desktop\re3.xls", 
			alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
			e(all)  excel replace;

gen sample3re = e(sample);
			
			
****************************
*Plot of M3 with random effects
****************************
#delimit;
	predict p1, pr;
	label variable interact_dir "Border accessibility";
	
	graph twoway 
		(histogram interact_dir if sample3==1, percent scheme(s1mono)  yaxis(1)  ytitle("Percentage of Observations",size(medlarge) 		axis(1)))
		(lfitci p1  interact_dir if sample3==1 & lagwall==0, lcolor(gs2) lpattern(dash dot) yaxis(2) clwidth(thick) ytitle("", 	size(medlarge) axis(2)) )  
		(lfitci p1  interact_dir if sample3==1 & lagwall==1, lcolor(gs2)  xtitle(, size(medlarge)) yaxis(2) clwidth(thick) ytitle("Pr(Militant group emergence)", 		size(medlarge) axis(2)) 
		),
		legend(order(5 "Border fortification=1" 3 "Border fortification=0" 2 "95% CI" 1 "Border accessibility") col(1) ); 

#delimit;
	graph export "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\text\REplot.pdf",		as(pdf)   replace;

drop p1;



	
	
 
****************************
*APPENDIX D2: BIVARIATE PROBIT
****************************




*selection model
btscs startwall year dyadid , g(sw1) 
gen sw2 = sw1*sw1
gen sw3 = sw1 * sw1 *sw1
#delimit; 
biprobit (selection: startwall = lagwar interact_dir  lagloginequality lagrepress laglnref lagmid lagally lagethsim  lagreceiverdem lagreceivercaplarge sw*    ) 
(outcome: receiveremerge =  c.interact_dir##i.lagwall lagwar lagloginequality lagrepress laglnref lagmid lagally lagethsim  lagreceiverdem lagreceivercaplarge py* ) 
 if senderpersist==1  , robust cl(dyad2) ;
  outreg2 using "C:\Users\Chris\OneDrive\Desktop\Results\selectionmodel", title("Basic Model") ctitle("") addnote("Probability Levels Two-tailed") e(all) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) stats(coef se) bdec(2) sdec(2) excel replace;

 
 
****************************
*APPENDIX D1: USE CIRI DATA TO TEST DOMESTIC MOVEMENT RESTRICTIONS
****************************


 
#delimit;
logit receiveremerge i.lagwall##c.interact_dir lagwar lagloginequality  lagformov laglnref  lagally lagethsim lagmid  lagreceiverdem lagreceivercaplarge py*  
	 if   senderpersist==1 & year > 1975 , robust cl(dyad2);
	 
	 
				outreg2 using "C:\Users\Chris\OneDrive\Desktop\cirimodel.xls", 
			alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) bdec(2) sdec(2)
			e(all)  excel replace;
	
	
	

****************************
*TABLE 3 and 7: SUMMARY STATS
****************************

* (EDTG)
#delimit;
sum receiveremerge lagwall interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem lagreceivercaplarge if sample2==1;

* (Jones and Libicki)
#delimit;
sum receiverbinaryemerge lagwall interact_dir lagwar lagloginequality  lagrepress laglnref  lagally lagethsim lagmid  lagreceiverdem lagreceivercaplarge if sample2==1;

 
 
 
****************************
*FIGURES 2 and 3
****************************



*Militant persistence over time (jones and libicki);
clear;
use "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\data\jones and libicki group persistence.dta", clear;
replace grouponset_ccode2 = 0 if grouponset_ccode2==.;
collapse (sum) grouponset_ccode2 , by(year);
twoway bar grouponset_ccode2 year if year > 1975 & year < 2007, scheme(s1mono) xscale(range(1975(5)2010)) yscale(range(0 12)) xtitle("Year") ytitle("Frequency of Militant Group Emergence");

	graph export "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\text\jones-persistence.eps",		as(eps)   replace;
 
 
*Militant persistence over time (EDTG);
clear;
use "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\data\sandler group persistence.dta", clear;
replace emergence = 0 if emergence==.;
collapse (sum) emergence_ccode1 , by(year);
twoway bar emergence_ccode1 year if year > 1975 & year < 2014, scheme(s1mono) xscale(range(1975(5)2015)) yscale(range(0 25)) xtitle("Year") ytitle("Frequency of Militant Group Emergence");

	graph export "C:\Users\Chris\Dropbox\Research\Diffusion and Fortifications\text\sandler-persistence.eps",		as(eps)   replace;
 

 
 
 
clear;
 
 
 
log close;
 
 
 
 
